{% set template = haproxy_template.vmware_view_cs %}
# VMware View Connection Server Defaults
defaults
	# Default to HTTP mode
	mode http

	# Retry another server on connection failure
	option redispatch

	# Timeouts
	timeout connect            5s
	timeout http-keep-alive    1s
	timeout http-request       15s
	timeout queue              30s
	timeout tarpit             1m
	timeout client             300s
	timeout server             300s

	# Logging options
	option httplog
	option dontlognull
	log global

	# Set default balancing algorithm
	balance leastconn

	# Default server check options
{% if proxy.defaults is defined %}
	default-server inter {{ proxy.defaults.interval|default(template.interval) }} rise {{ proxy.defaults.rise|default(template.rise) }} fall {{ proxy.defaults.fall|default(template.fall) }}
{% else %}
	default-server inter {{ template.interval }} rise {{ template.rise }} fall {{ template.fall }}
{% endif %}

{% if proxy.peers is defined %}
# Peers to sync session affinity between
peers peers_{{ name }}
{% for peer in proxy.peers %}
	peer {{ peer.name }} {{ peer.ip }}:{{ peer.port }}
{% endfor %}
{% endif %}

# VMware View Connection Server Front-End
frontend fe_{{ name }}
	# Listen on HTTP (80) and HTTPS (443)
{% for bind in proxy.frontend.bind %}
	bind {{ bind.ip }}:80
	bind {{ bind.ip }}:443 ssl crt {{ bind.crt }}
{% endfor %}

	# Redirect HTTP -> HTTPS
	redirect scheme https code 301 if !{ ssl_fc }

	# Use View Connection Server Back-End
	use_backend be_{{ name }}

# View Connection Server Back-End

backend be_{{ name }}

	# Maintain affniity based on JSESSIONID cookie
	stick match req.cook(JSESSIONID)
	stick store-response res.cook(JSESSIONID)
{% if proxy.peers is defined %}
	stick-table type string size 2k expire {{ proxy.backend.session_expiry|default("1h") }} peers peers_{{ name }}
{% elif haproxy_peers is defined %}
	stick-table type string size 2k expire {{ proxy.backend.session_expiry|default("1h") }} peers peers_global
{% else %}
	stick-table type string size 2k expire {{ proxy.backend.session_expiry|default("1h") }}
{% endif %}

	# View Connection servers
{% for server in proxy.backend.server %}
	server {{ server.name }} {{ server.ip }}:443 ssl check ca-file {{ server.ca_file }}
{% endfor %}
